const wx = require('jweixin-module')

import * as weixinApi from '@/server/api/weixin/weixin.js'

const wxShare = async function () {
  const url = document.location.href
  const urlData = {
    url: encodeURIComponent(url.split('#')[0])
  }
  await weixinApi.getConfig(urlData).then((e) => {
    if (e.success) {
      let data = JSON.parse(e.data)
      wx.config({
        debug: false,
        appId: data.appId,
        timestamp: data.timestamp,
        nonceStr: data.nonceStr,
        signature: data.signature,
        jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'],
        openTagList: ['wx-open-launch-app']
      })
    }
  })
}

export { wxShare }
